package cn.nupt.controller;



import java.util.Scanner;

import cn.nupt.model.Member;
import cn.nupt.model.MemberRecord;
import cn.nupt.service.MemberRecordService;
import cn.nupt.service.MemberService;
import cn.nupt.service.SecondaryCardService;
import cn.nupt.service.YearCardService;

public class Yoga {
	
	//输入会员信息
	public static Member inputMember(Scanner scanner){	 
		String inputStr = scanner.next();
		String [] strArray = inputStr.split(",");
		String name =strArray[0];
		String phone=strArray[1];
		String address=strArray[2];
		String job=strArray[3];
		Member member = new Member();
		member.setName(name);
		member.setPhone(phone);
		member.setAddress(address);
		member.setJob(job);
		return member;
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		MemberService memberService = new MemberService();
		
		//添加第一位会员
		Member member1 = inputMember(scanner);
		int row1 = memberService.addMember(member1);
		int id1 = 0;
		if(row1>0){//如果插入成功，则返回会员卡的编号
		    id1 = memberService.searchMemByPhone(member1.getPhone()).getMemberId();
			System.out.println("当前会员编号："+id1);
		}else{
			System.out.print("会员添加失败！");
		}
		
		//添加第二位会员
		Member member2 = inputMember(scanner);
		int id2 = 0;
		int row2 = memberService.addMember(member2);
		if(row2>0){//如果插入成功，则返回会员卡的编号
		    id2 = memberService.searchMemByPhone(member2.getPhone()).getMemberId();
			System.out.println("当前会员编号："+id2);
		}else{
			System.out.print("会员添加失败！");
		}
		
		
		//绑定第一位会员年卡
		//先创建一张年卡
		YearCardService yearCardService = new YearCardService();
		int yearCardId = yearCardService.addYearCard();
		MemberRecord memberRecord1 = new MemberRecord();
		memberRecord1.setMemberId(id1);
		memberRecord1.setCardId(yearCardId);
		memberRecord1.setCardType(1); //假设年卡类型为1
		
		MemberRecordService memberRecordService1 = new MemberRecordService();
		memberRecordService1.addMemberRecord(memberRecord1);
		System.out.println("A new 年卡 added to "+member1.getName()+"("+id1+")");
		
		//绑定第二位会员次卡
		//先创建一张次卡
		SecondaryCardService secondaryCardDAOImpl = new SecondaryCardService();
		int secCardId = secondaryCardDAOImpl.addSecondaryCard(id2, 100);
		MemberRecord memberRecord2 = new MemberRecord();
		memberRecord2.setMemberId(id2);
		memberRecord2.setCardId(secCardId);
		memberRecord2.setCardType(2);//假设次卡类型为2
		MemberRecordService memberRecordService2 = new MemberRecordService();
		memberRecordService2.addMemberRecord(memberRecord2);
		System.out.println("A new 次卡 added to "+member2.getName()+"("+id2+")");
		
	}//main end

}
